/**
 * @Company:中享思途   
 * @Title:UserManagerController.java 
 * @Author:IL Clown   
 * @Date:2020年8月18日 上午10:17:46     
 */
package com.situ.shopsystem.controller;

import java.io.Serializable;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.shopsystem.pojo.LayuiResult;
import com.situ.shopsystem.pojo.User;
import com.situ.shopsystem.service.UserService;

/** 
 * @ClassName:UserManagerController 
 * @Description:后台页面的的数据操作
 * 
 * 
 * 
 * manager/user/checkUserName
 * manager/user/doAddOrUpdate
 * manager/user/doAdd
 * manager/user/showAdd
 * manager/user/doLogin
 * 
 * 
 * 
 * 
 */

@Controller
@RequestMapping("/manager/user/")
public class UserManagerController implements Serializable {
	private static final long serialVersionUID = 1L;

	@Autowired
	private UserService userService;

	//这是用来做登录的
	@ResponseBody
	@RequestMapping("doLogin")
	public LayuiResult doLogin(String userCode, String userPass, HttpSession session) {
		User user = userService.findUserByIdAndPass(userCode, userPass);
		if (user == null) {
			return new LayuiResult(1, "登录失败", null, null);

		} else {
			session.setAttribute("loginUser", user);
			return new LayuiResult(0, null, null, null);
		}
	}
    //后台页面显示所有用户信息
	@ResponseBody
	@RequestMapping("findAll")
	public LayuiResult findAll(Integer page, Integer limit, User user) {
		return userService.findAllManager(page, limit, user);
	}
    //显示添加页面
	@RequestMapping("showAdd")
	public String showAdd() {
		return "manager/user/user_add_edit";

	}
    //进行添加或修改操作
	@ResponseBody
	@RequestMapping("doAddOrUpdate")
	public int doAddOrUpdate(User user, HttpSession session) {
		if (user.getRowId() == null) {
			return userService.save(user, session);
		} else {
			return userService.update(user, session);
		}

	}
     
	/*	@ResponseBody
		@RequestMapping("doUpdate")
		public int doUpdate(User user, HttpSession session) {
			return userService.save(user, session);
		}*/
    //根据用户姓名查找
	@ResponseBody
	@RequestMapping("checkUserName")
	public int checkUserName(String userId) {
		return userService.findByUserId(userId);
	}
    //对数据进行删除
	@ResponseBody
	@RequestMapping("delete")
	public int delete(Long rowId) {
		return userService.delete(rowId);
	}

}
